package com.newedu.equipmgr.servlet.system.permission;

import com.alibaba.fastjson.JSON;
import com.newedu.equipmgr.entity.SysPermissionMenuVO;
import com.newedu.equipmgr.service.SysPermissionService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

/**
 * @author jerry
 * @create 2020-06-12 09:11:59
 * @company 新开普电子股份有限公司
 *
 * 根据用户查询对应的权限菜单信息
 */
@WebServlet(name = "PermissionMenuByUserServlet",urlPatterns = "/api/servlet/permission/menubyuserid")

public class PermissionMenuByUserServlet extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doPost(req,resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        String userid = req.getParameter("userid");

        SysPermissionService sysPermissionService = new SysPermissionService();
        List<SysPermissionMenuVO> sysPermissionMenuVOList = sysPermissionService.queryPermissionListBy(userid);

        String jsonString = JSON.toJSONString(sysPermissionMenuVOList);

        PrintWriter out = resp.getWriter();
        out.println(jsonString);
        out.flush();
        out.close();
    }
}
